﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion


#region Usings



#endregion

using System.Windows;
using ScrumTable.UI.View.Controls;
using ScrumTable.UI.View.Extension;
using ScrumTable.UI.ViewModel;

namespace ScrumTable.UI.View.WinTouch.UserControls.PlanningPoker
{
    /// <summary>
    /// Interaction logic for ScrumPokerCardControl.xaml
    /// </summary>
    public partial class ScrumPlanningPokerCardControl : IDropUserControl
    {
        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------

        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------
        
        public double? Value
        {
            get
            {
                var card = DataContext as ScrumPokerCard;
                if (card != null && card.CardType == ScrumPokerCardType.Number)
                {
                    return card.Number;
                }
                return null;
            }
        }

        #endregion

        #region Constructors / Destructor
        /// <summary>
        /// Initializes a new instance of the <see cref="ScrumPokerCardControl"/> class.
        /// </summary>
        public ScrumPlanningPokerCardControl()
        {
            if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
            {
                InitializeComponent();
              }
        }

  
        #endregion

     
        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------


        #endregion

        #region Events
        //--------------------------------------------------------------------
        // Events
        //--------------------------------------------------------------------

        private void OnDrop(object sender, Microsoft.Surface.Presentation.SurfaceDragDropEventArgs e)
        {
            if(CanDrop(e.Cursor.Data) == CanDropResult.CanDrop)
            {
                if (Value.HasValue)
                {
                    ((UserStoryViewModel) e.Cursor.Data).StoryPoints = Value.Value;
                }
            }
        }



        #endregion


        #region IDropUserControl Members

        public FrameworkElement GetRootControl
        {
            get { return RootGrid; }
        }

        public bool ShowIconWithbackground
        {
            get { return true; }
        }

        public CanDropResult CanDrop(object objectToDrop)
        {
            return this.ConvertBoolToEnum(objectToDrop is UserStoryViewModel);
        }

        #endregion
    }
}
